<template>
  <div>
    <el-row>
      <el-col :span="24" class="addRole">
        <!-- 查询 -->
        <el-popover placement="bottom-start" width="1000" style="margin-right:10px;" trigger="click">
          <el-form :inline="true" :model="search">
              <el-form-item label="图纸编号" >
                  <el-input v-model="search.drawCode"></el-input>
              </el-form-item>
              <el-form-item label="生产令号" >
                  <el-input v-model="search.makeNo"></el-input>
              </el-form-item>
              <el-button type="primary" @click="searchBtn">确认</el-button>
          </el-form>
          <el-button slot="reference" type="primary" icon="el-icon-search">查询</el-button>
        </el-popover>
      </el-col>
    </el-row>
    <!-- 29所列表 -->
    <tableList29 ref="tableList29" :postData="postData">
      <template v-slot:default="scope">
        <el-button @click="showDialog('update',scope.row)" type="text" size="small">详情</el-button>
        <el-button @click="confirmHandle(scope.row)" type="text" size="small"><span  class="cl-danger">到料</span></el-button>
      </template>
    </tableList29>
  
    <!-- 计划任务详情 -->
    <el-dialog class="bodyNopaddingTop" :title="dialog.title" :visible.sync="dialog.isShow"  v-dialogDrag width="1100px"  @opened="openedDialog">
      <el-tabs v-model="dialog.activeName" @tab-click="dialogHandleClick">
        <el-tab-pane label="详情" name="1">
          <taskDetail29 :detailObj="dialog.formData" :type="dialog.type" :editDisalbe="true"></taskDetail29>
        </el-tab-pane>
        <el-tab-pane label="29所工艺" name="2" v-if="dialog.type==='update'">
          <!-- <el-button type="primary" @click="showDialog1('insert')">新增</el-button> -->
          <processPlanList29 :data="dialog.formData" ref="processPlanList29Ref">
              <template v-slot:default="scope">
                <el-button @click="showDialog1('update',scope.row)" type="text" size="small">详情</el-button>
              </template>
          </processPlanList29>
        </el-tab-pane>
        <el-tab-pane label="图纸上传" name="3" v-if="dialog.type==='update'">
          <uploadList :upLoadType="1" :drawNo="dialog.drawCode"  ref="drawing"></uploadList>
        </el-tab-pane>
        <el-tab-pane label="工艺上传" name="4" v-if="dialog.type==='update'">
           <uploadList :upLoadType="2" :drawNo="dialog.drawCode"  ref="technology"></uploadList>
        </el-tab-pane>
        <el-tab-pane label="图形文件上传" name="5" v-if="dialog.type==='update'">
           <uploadList :upLoadType="3" :drawNo="dialog.drawCode"  ref="graphicsFile"></uploadList>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>
    <!-- 新增编辑29所计划任务详情 -->
    <el-dialog class="bodyNopaddingTop" :title="dialog1.title" :visible.sync="dialog1.isShow" v-dialogDrag>
       <processPlanDetail29 :formData="dialog1.formData" :type="dialog1.type" :tid="dialog.formData.tid" :disabled='true'></processPlanDetail29>
    </el-dialog>
  </div>
</template>
<script>
import pdf from 'vue-pdf';
import planApi from 'plugins/axios/planApi.js';
import baseApi from 'plugins/axios/baseApi.js';
import materielApi from 'plugins/axios/materielApi.js';
import uploadList from 'views/components/uploadList.vue' /**1-图纸上传、2-工艺上传、3-图形文件上传 的列表组件 */
import tableList29 from 'views/components/tableList29.vue' /**29所列表组件 */
import taskDetail29 from 'views/components/taskDetail29.vue' /**29所任务详情组件 */
import processPlanList29 from 'views/components/processPlanList29.vue' /**29所工序列表组件 */
import processPlanDetail29 from 'views/components/processPlanDetail29.vue' /**29所工序详情组件 */
export default {
  components: {
    pdf,
    uploadList,
    tableList29,
    taskDetail29,
    processPlanList29,
    processPlanDetail29
  },
  data(){
    return {
      loading:false,
      postData:{
        isUploadDraw:1,
        isMaterialArrvie:0,
        isMaterialTailor:0
      },/**表格列表 */
      machineAllList:[],/**所有机器列表 */
      search:{
        drawCode:"",
        makeNo:""
      },
      dialog:{/**弹框配置 */
        title:'',
        isShow:false,
        type:'',
        formData:{},
        activeName:'2',
        otherUpDataData:{},
        drawCode:''
      },
      dialog1:{
        title:'',
        type:'',
        isShow:false,
        formData:{}
      }
    }
  },
  created(){},
  mounted(){
    this.getTablList();
  },
  methods:{
    getTablList(){/**计划列表 */
      let self = this;
      self.postData.drawCode=self.search.drawCode;
      self.postData.makeNo=self.search.makeNo;
      self.postData.isMaterialArrvie ='0';
      self.$refs.tableList29.get29TableList()
    },
    /**点击搜索*/ 
    searchBtn(){
      this.getTablList();
    },
    showDialog(type,row){
      this.dialog.activeName='2';
      this.dialog.type = type
      switch(type){
        case 'insert':
          this.dialog.isShow=true;
          this.dialog.formData={};
          this.dialog.title = '新增计划任务';
          break;
        case 'update':
          this.dialog.isShow=true;
          this.dialog.formData = row;
          this.dialog.title = '计划详情';
          this.dialog.drawCode = row.drawCode; 
          this.dialog.otherUpDataData.drawNo=row.drawCode;
          break;
        case 'print':
           this.dialog.formData = row;
           this.$refs.print1.getCgPdfData(row.id);
          break;
      } 
    },
    showDialog1(type,row){
      this.dialog1.isShow=true;
      this.dialog1.type=type;
      switch(type){
        case 'insert':
          this.dialog1.formData={};
          this.dialog1.title = '新增29所工艺详情';
          break;
        case 'update':
          this.dialog1.formData = row;
          this.dialog1.title = '编辑29所工艺详情';
          break;
      }
    },
    /**详情切换tab*/ 
    dialogHandleClick(){
      let self = this;
      switch(self.dialog.activeName){
        case '2':
          self.$refs.processPlanList29Ref.getProcessPlanList();
          break;
         case '3':
           self.$refs.drawing.getTableList();
          break;
         case '4':
           self.$refs.technology.getTableList();
          break;
        case '5':
          self.$refs.graphicsFile.getTableList();
          break;
      }
    },
     /**打开弹框*/ 
    openedDialog(){
      if(this.dialog.type==='update'&&this.dialog.activeName==='2'){
        this.$refs.processPlanList29Ref.getProcessPlanList();
      }
    },
    /**确认到料*/ 
    confirmHandle(row){
      let self  = this;
      self.$confirm('是否确认已到料?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        materielApi.materialArrive(row.id).then(res=>{
          self.$message.success("确认成功")
          self.getTablList();
        })
      }).catch(()=>{})
    }
  }
}
</script>
<style lang="stylus" scoped>
  .addRole
    padding-bottom 10px
</style>
